package com.zc.operator.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.operator.domain.ChargeCar;
import com.zc.operator.service.IChargeCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 汽车库Controller
 *
 * @author glb
 * @date 2023-05-26
 */
@RestController
@RequestMapping("/operator/car")
public class ChargeCarController extends BaseController
{
    @Autowired
    private IChargeCarService chargeCarService;

    /**
     * 查询汽车库列表
     */
    @PreAuthorize("@ss.hasPermi('operator:car:list')")
    @GetMapping("/list")
    public AjaxResult list(ChargeCar chargeCar)
    {
        List<ChargeCar> list = chargeCarService.selectChargeCarList(chargeCar);
        return AjaxResult.success(list);
    }

    /**
     * 导出汽车库列表
     */
    @PreAuthorize("@ss.hasPermi('operator:car:export')")
    @Log(title = "汽车库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeCar chargeCar)
    {
        List<ChargeCar> list = chargeCarService.selectChargeCarList(chargeCar);
        ExcelUtil<ChargeCar> util = new ExcelUtil<>(ChargeCar.class);
        util.exportExcel(response, list, "汽车库数据");
    }

    /**
     * 获取汽车库详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:car:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return AjaxResult.success(chargeCarService.selectChargeCarByCarId(carId));
    }

    /**
     * 新增汽车库
     */
    @PreAuthorize("@ss.hasPermi('operator:car:add')")
    @Log(title = "汽车库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeCar chargeCar)
    {
        return toAjax(chargeCarService.insertChargeCar(chargeCar));
    }

    /**
     * 修改汽车库
     */
    @PreAuthorize("@ss.hasPermi('operator:car:edit')")
    @Log(title = "汽车库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeCar chargeCar)
    {
        return toAjax(chargeCarService.updateChargeCar(chargeCar));
    }

    /**
     * 删除汽车库
     */
    @PreAuthorize("@ss.hasPermi('operator:car:remove')")
    @Log(title = "汽车库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(chargeCarService.deleteChargeCarByCarIds(carIds));
    }

    /*
    * 汽车树形
    * */
    @GetMapping("/listTree")
    public AjaxResult listTree(ChargeCar chargeCar)
    {
        List<Map> list = chargeCarService.selectChargeCarTreeList(chargeCar);
        return AjaxResult.success(list);
    }
}
